package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbAddressMapper;
import com.bw1806.pojo.TbAddress;
import com.bw1806.pojo.TbAddressExample;
import com.bw1806.sellergoods.service.TbAddressService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbAddressServiceImpl implements TbAddressService {

    @Autowired
    private TbAddressMapper tbAddressMapper;

    @Override
    public List<TbAddress> findAll() {
        return tbAddressMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbAddress> pagelist(TbAddress tbAddress,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbAddressExample example=new TbAddressExample();

        TbAddressExample.Criteria criteria = example.createCriteria();

        if(tbAddress!=null){
            //if(tbAddress.getName()!=null && tbAddress.getName().length()>0){
            //    criteria.andNameLike("%"+tbAddress.getName()+"%");
           // }
        }

        Page<TbAddress> page= (Page<TbAddress>) tbAddressMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbAddress tbAddress) {
        Long id = tbAddress.getId();
        if(id != null && id !=0){
            tbAddressMapper.updateByPrimaryKey(tbAddress);
        } else{
            tbAddressMapper.insert(tbAddress);
        }
    }

    @Override
    public TbAddress getById(Long id) {
        return tbAddressMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbAddressMapper.deleteByPrimaryKey(id);
        }
        //tbAddressMapper.deletebth(ids);
    }
}
